package com.zb.demo.controller;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.zb.entity.Flight;
import com.zb.demo.service.FlightService;
import com.zb.util.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Controller
@RequestMapping(value = "/flight")
public class FlightController {
    @Autowired
    private FlightService fs;

    @RequestMapping("/toindex")
    public  String toindex(){
        return "index";
    }

    @RequestMapping("/show")
    @ResponseBody
    public  Object show(Integer pageIndex,Integer departureCity,Integer arrivalCity){
        PageUtil<Flight> pageUtil = fs.getFlightsByConds(pageIndex, 3, departureCity, arrivalCity);
        return JSONObject.toJSONString(pageUtil, SerializerFeature.DisableCircularReferenceDetect);
    }

    @RequestMapping("/add")
    @ResponseBody
    public  Object add(Flight flight){
        Map<String, Object> map = fs.add(flight);
        return JSONObject.toJSONString(map, SerializerFeature.DisableCircularReferenceDetect);
    }

    @RequestMapping("/check")
    @ResponseBody
    public  Object check(String flightNo){
        Map<String, Object> map = fs.getFlightByflightNo(flightNo);
        return JSONObject.toJSONString(map, SerializerFeature.DisableCircularReferenceDetect);
    }
}
